package com.example.demo.Dao;

import com.example.demo.Entity.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;

/**
 * PersonRepository
 * //https://blog.csdn.net/qq_42928918/article/details/90310863
 * @blame Android Team
 */
public interface PersonRepository extends JpaRepository<Person,Long> {
    Person findByUsername(String userName);
    Person findByOpenId(String openId);

//    @Modifying
//    @Query(value="update Person p " +
//            "set p.area = #{#per.area} , p.updatedTime = current_date , p.isHealth = #{#per.isHealth} ," +
//            "p.password = #{#per.password} , p.username = #{#per.username} , p.realName =#{#per.realName} , p.role = #{#per.role} ")

    @Modifying
    @Query(value="update Person  p set p.realName = ?1 , p.updatedTime = ?3  where p.username  = ?2 ")
    int  updateRealName(String newName, String userName, Date curDate);
    @Modifying
    @Query(value="update Person  p set p.area = ?1 , p.updatedTime = ?3  where p.username  = ?2 ")
    int  updateArea(String area,String userName,Date curDate);
    @Modifying
    @Query(value="update Person  p set p.openId = ?1 , p.updatedTime = ?3  where p.username  = ?2 ")
    int associateOpenIdWithUserName(String openId,String userName,Date curDate);
    @Modifying
    @Query(value = "update Person  p set p.openId = null where  p.username = ?1")
    int cancelAssociate(String userName);
}
